package com.polaris.live.widget.circle

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.core.view.isVisible
import com.polaris.live.databinding.WidgetCircleCountDownBinding

/**
 * 圆环倒计时
 *
 * @author Created by 半仙 on 2023/10/27/027 19:50
 */
class CircleCountDownView(context: Context, attributeSet: AttributeSet) : FrameLayout(context, attributeSet) {

    private val mBinding = WidgetCircleCountDownBinding.inflate(LayoutInflater.from(context), this)

    init {
        viewGone()

        mBinding.circleRun.setAnimationCallback {
            visibility = INVISIBLE
            onAnimationEnd?.invoke()
        }
        mBinding.circleRun.setAnimationStartCallback {
            visibility = VISIBLE
        }
    }

    var onAnimationEnd: (() -> Unit)? = null

    fun setAnimationCallback(callback: () -> Unit) {
        onAnimationEnd = callback
    }


    fun anewRun() {
        mBinding.circleRun.anewRun()
    }

    fun viewGone() {
        visibility = INVISIBLE
    }

    fun showView() {
        if (isVisible) {
            return
        }

        visibility = VISIBLE
        anewRun()
    }
}